package fmi.chesstern.pieces.strategy;

import java.util.HashSet;
import java.util.Set;


import fmi.chesstern.game.BoardField;
import fmi.chesstern.game.GameBoardState;
import fmi.chesstern.pieces.ChessPiece;
import fmi.chesstern.pieces.ChessPieceColor;

public class StrategyUtilities {
	public static final boolean canPositionOn(GameBoardState board, BoardField position, ChessPieceColor color) {
		if (!board.isFieldInBoard(position)) {
			return false;
		}
		
		ChessPiece pieceAtPosition = board.getPieceAt(position);
		
		return (pieceAtPosition == null || pieceAtPosition.getColor() != color);
	}
	
	public static final Set<BoardField> getContinuousMoves(GameBoardState board, BoardField currentPosition, int deltax, int deltay) {		
		Set<BoardField> result = new HashSet<BoardField>();
		
		ChessPieceColor color = board.getPieceAt(currentPosition).getColor();
		
		while (true) {
			currentPosition = currentPosition.offsetBy(deltax, deltay);
			
			if (!canPositionOn(board, currentPosition, color)) {
				break;
			}
			
			result.add(currentPosition);
			
			if (board.getPieceAt(currentPosition) != null) {
				break;
			}
		}
		
		
		return result;
	}
}
